<template>
  <div>
    <div class="bg_grey_all"></div>
    <van-row>
      <van-col span="24" class="title">
        <span style="color: white">浩物安全管理系统</span>
      </van-col>
    </van-row>
    <van-row class="topMargin">
      <van-col span="24">
        <van-card class="bg_blue" :thumb="head_image">
          <template #title>
            <div style="font-size: 18px">{{ currentUser.name }}</div>
            <!-- <div style="font-size:14px;color:#cccccc">销售部-销售经理</div> -->
            <div style="font-size: 14px; margin-top: 20px">
              {{ currentUser.companyName }}
            </div>
          </template>
        </van-card>
      </van-col>
    </van-row>

    <van-row>
      <van-col span="24" class="bg_grey_height"></van-col>
    </van-row>
    <van-row>
      <van-col span="24">
        <van-cell-group>
          <van-cell
            title="账号与安全"
            icon="setting-o"
            is-link
            @click="redirectSubPage('account')"
          />
        </van-cell-group>
      </van-col>
    </van-row>
    <van-row>
      <van-col span="24" class="bg_grey_height"></van-col>
    </van-row>
    <van-row>
      <van-col span="24">
        <van-cell-group>
          <van-cell
            title="实名信息"
            icon="idcard"
            :value="isHasRealNameData + '   ' + realNameStatus"
            is-link
            @click="redirectSubPage('idcard')"
          />
          <van-cell
            title="驾驶资质"
            icon="manager-o"
            :value="isHasDriverData + '   ' + driverStatus"
            is-link
            @click="redirectSubPage('drivingLicense')"
          />
        </van-cell-group>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import { Toast } from 'vant';
import { Api, base_uri } from "../../api/api_config";

export default {
  data() {
    return {
      currentUser: {},
      head_image: "",
      base_uri: "",
      certList: [],
      isHasRealNameData: '',
      isHasDriverData: '',
      realNameStatus: '',
      driverStatus: '',
      realNameObj: {},
      driverObj: {}
    };
  },
  created() {
    this.initData();
  },
  methods: {
    initData() {
      this.base_uri = base_uri;
      this.$store.state.tab_show = true;
      this.currentUser = this.$store.state.configuration.currentUser;
      this.getUserAvatar();
      this.getCertificationData();
    },
    redirectSubPage(e) {
      if (e === 'idcard') {
        if (this.isHasRealNameData === '已提交') {
          if (this.realNameStatus !== '已拒绝') {
            Toast('您无需再次提交审核。');
            return;
          }
        }
        this.certObj = this.realNameObj
      } else if (e === 'drivingLicense') {
        if (this.isHasDriverData === '已提交') {
          if (this.driverStatus !== '已拒绝') {
            Toast('您无需再次提交审核。');
            return;
          }
        }
        this.certObj = this.driverObj
      }
      this.$store.state.certObj = this.certObj;
      this.$store.state.tab_show = false;
      this.$router.push("/personalInfo/" + e);
    },
    getUserAvatar() {
      let that = this;
      this.$axios({
        method: Api.file.file.method,
        url:
          Api.file.file.url + "?linkid=" + this.currentUser.id + "&filetype=8",
      })
        .then(function (res) {
          that.head_image = that.base_uri + res.data[0].file_path;
        })
        .catch(function (e) {
          console.log(e);
        });
    },
    getCertificationData() {
      let that = this;
      this.$axios({
        method: Api.certification.certification.method,
        url:
          Api.certification.certification.url +
          "?UserId=" +
          this.currentUser.id,
      })
        .then(function (res) {
          that.certList = res.data.items;
          that.executeData();
        })
        .catch(function (e) {
          console.log(e);
        });
    },
    executeData() {
      this.isHasRealNameData = "未提交";
      this.isHasDriverData = "未提交";
      this.realNameStatus = "";
      this.driverStatus = "";
      this.certList.forEach((element) => {
        if (element.type === 1) {
          this.isHasRealNameData = "已提交";
          this.realNameStatus = this.getText(element.status);
          this.realNameObj = element
        }
        if (element.type === 2) {
          this.isHasDriverData = "已提交";
          this.driverStatus = this.getText(element.status);
          this.driverObj = element
        }
      });
    },
    getText(flag) {
      var text = "";
      switch (flag) {
        case 1:
          text = "审批中";
          break;
        case 2:
          text = "已通过";
          break;
        case 3:
          text = "已拒绝";
          break;
      }
      return text;
    },
  },
};
</script>

<style scoped>
</style>